package com.fast.fastenjoy.base.web.tag.tagtemplate;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

import com.fast.fastenjoy.base.utils.StringExUtils;

public abstract class TagTemplate {
	
	private static final Logger LOG = Logger.getLogger(TagTemplate.class);
	
	private static Map<String, String> TAG_TEMPLATE_CACHE = new HashMap<String, String>();
	
	public TagTemplate(){
		
		if(LOG.isInfoEnabled()){
			LOG.info("===========Get TagTemplate begin");
		}
		
		try{
			Map<String, String> allTagTemplate = getAllTagTemplate();
			
			if(allTagTemplate != null){
				TAG_TEMPLATE_CACHE.putAll(allTagTemplate);
			}else{
				// TODO 报告异常
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public String getTagTemplate(String classPath){
		
		if(classPath == null){
			return StringExUtils.EMPTY;
		}
		
		String tagTemplate = TAG_TEMPLATE_CACHE.get(classPath);
		
		return tagTemplate == null ? StringExUtils.EMPTY : tagTemplate;
	}
	
	public abstract Map<String, String> getAllTagTemplate();
	
}
